package com.voice.core.utils;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class ThreadFactoryUtil {

    public static ThreadFactory threadFactory(){
        return threadFactory("IOSelectorContext Pool");
    }

    public static ThreadFactory threadFactory(String prefix){
        return new ThreadFactory() {
            private AtomicInteger threadNumber = new AtomicInteger(1);
            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r, prefix + "-thread-" + threadNumber.getAndIncrement());
                return thread;
            }
        };
    }
}
